<!DOCTYPE html>
<?php

require_once ('conn.php');
require_once ('top.php');
if($_SESSION['role']==2){
     Header("Location:supply_index.php"); 
    }elseif($_SESSION['role']==3){
     Header("Location:dotlistMaster.php"); 
   }
$contactNumber = $_GET['contactNumber'];
$ci_contact = mysql_fetch_row(mysql_query("select id,name from ci_contact where number ='$contactNumber'"));
?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>优易购</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <link rel="stylesheet" href="css/jquery.lineProgressbar.css">
    <script src="js/jquery-1.11.0.min.js"></script>
    <script src="js/jquery.lineProgressbar.js"></script>
</head>
<body>
    <div class="top">
        <span onclick="javascript:history.go(-1);" class="fanhui">返回</span>
        <span><?=$ci_contact[1]?></span>
        <div class="tright"><span class="outlogin">退出登陆</span></div>
    </div>
    
    <?php
    $result=mysql_query("select t2.number as goodsnumber,t3.url as url,t2.name as name,sum(t1.qty) as num from ci_invoice_info as t1 inner JOIN ci_goods as t2 on t1.invId = t2.id INNER JOIN ci_goods_img t3 on t2.id=t3.invId

 where t1.buId =$ci_contact[0] and t1.transType = 150601 and t1.isDelete = 0 GROUP BY t2.number"); 
    $i=0;
    $but=0;
    while($row=mysql_fetch_array($result)) 
    {
        
        $total = $row['num'];
         $xiaoshou = mysql_fetch_row(mysql_query("select goodsNumber, sum(num) from ci_wx_order_goods where customerNumber='$contactNumber' and goodsNumber = '$row[goodsnumber]' and payStatus = 1 GROUP BY goodsNumber,customerNumber"));
        if($total<0)
        {
            $total = $total*-1;
        }
         $Surplus = mysql_fetch_row(mysql_query("select SUM(num) from ci_wx_order_goods where customerNumber ='$contactNumber'  and status=0 and payStatus = 1"));
        $but = $but + $Surplus[0];
        $Surplus = $total - $xiaoshou[1];//剩余
        
        if($Surplus==0&&$total==0){
            $Percentage = 0;
        }else{
            $Percentage = ($Surplus/$total)*100;
        }
        
    ?>
    <div class="list3">
        <div class="list100">
            <div class="goods">
                <img src="<?=$row['url']?>" alt="">
                <span class="goodname"><?=$row['name']?></span><br>
                <span class="goodnum">总共：<?=$total?> 剩余：<?=$Surplus?></span>
                <div class="jindu">
                     <div id="jindu<?=$i?>"></div>
                </div>
               
            </div>
        </div>
    </div>
    <script type="text/javascript">
		$(function(){
			$('#jindu<?=$i?>').LineProgressbar({
			  percentage: <?=$Percentage?>,
			  fillBackgroundColor: '#FF8601',
			  height: '10px',
			  radius: '50px'
			});
		})
	</script>
   <?php
    $i++;
    }
    ?>
    
    <div style=" width:100%;height:100px; float:left;"></div>
    
            <?php if($but>0){?>
                
                   <div class="goodsfootbut" id="buhuo">
                   全部补货
                   </div>

             <?php  }else{?>
       
               <div class="goodsfootbuthui">全部补货</div>
                <?php }?>
    
     
    
</body>
<script src="js/outlogin.js"></script>
<script>
$("#buhuo").click(function(){
         if(!confirm("是否确认补货？")){ 
             return false; 
            } 
    $.post("ajaxbuhuo.php",{buId:<?=$ci_contact[0]?>},function(data) {
	if(data=="y"){
      alert("已提交补货申请");
      history.go(0);
    }								
 });
});
</script>
	
</html>